package com.mew.chess.core.game.shbz.game.message;

import com.mew.chess.core.game.shbz.game.common.FishBO;
import com.mew.chess.core.game.shbz.game.common.FishTableUtil;
import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.*;

import java.util.ArrayList;
import java.util.List;


@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class TidePushMessage extends ZebraBaseMessage<TidePushMessage> {

    private long startTime;

    private int type;
    private byte scenarioNo;
    private int remainStep;   // 剩余步长；

    private List<FishBO> fishBOs = new ArrayList<>();

    public int getRemainStep(){
        //单位帧
        if (0 == this.startTime){
            this.startTime = System.currentTimeMillis();
            return 0;
        }

        return FishTableUtil.computeRemainStep(this.startTime);
    }

    @Override
    public void write(ByteBuf b) {

        writeInt(b,type);
        writeByte(b,scenarioNo);
        writeInt(b,getRemainStep());
        writeInt(b,fishBOs.size());
        for (FishBO fishBO : fishBOs) {
            fishBO.writeTide(b);
        }
    }

    @Override
    public TidePushMessage read(ByteBuf b) {
        return this;
    }
}
